package com.dzz.sjgl.controller;

import com.dzz.sjgl.entity.Dictionary;
import com.dzz.sjgl.entity.SentenceInfo;
import com.dzz.sjgl.service.ISentenceService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author KRIC
 * @ClassName WordController
 * @Date: 2019/3/13 11:09
 * @Description:
 */
@Controller
@ResponseBody
@RequestMapping("/sentence")
public class SentenceController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private final ISentenceService sentenceService;

    @Autowired
    public SentenceController(ISentenceService sentenceService) {
        this.sentenceService = sentenceService;
    }

    @ApiOperation(value = "通过关键字、或者试卷ID查询句子信息")
    @ResponseBody
    @GetMapping("/getList")
    public Map<String, Object> getList(int pageNum, int pageSize, String sentence, Integer paperId, String province, String exam, Integer minYear, Integer maxYear) {
        return sentenceService.findAllByQuery(pageNum, pageSize, sentence, paperId, province, exam, minYear, maxYear);
    }

//    @ApiOperation(value = "通过关键字查询统计")
//    @ResponseBody
//    @GetMapping("/getCount")
//    public Map<String, Object> getCount(String word) {
//        return sentenceService.getCount(word);
//    }

    @ApiOperation(value = "词频查询，单词、词频、省份、高/中考、年份")
    @ResponseBody
    @GetMapping("/getCp")
    public Map<String, Object> getCp(int pageNum, int pageSize, String word, Integer minCp, String province, String exam, Integer minYear, Integer maxYear) {
        return sentenceService.getCp(pageNum, pageSize, word, minCp, province, exam, minYear, maxYear);
    }

    @ApiOperation(value = "查询单词出现在的试卷列表，单词、省份、高/中考、年份")
    @ResponseBody
    @GetMapping("/getPaperByWord")
    public Map<String, Object> getPaperByWord(int pageNum, int pageSize, Integer wordId, String province, String exam, Integer minYear, Integer maxYear, String word) {
        return sentenceService.getPaperByWord(pageNum, pageSize, wordId, province, exam, minYear, maxYear, word);
    }

    @ApiOperation(value = "字典表通用查询 可选参数：类型、名称、编码   type: 省份（province） 考试等级（exam）")
    @ResponseBody
    @GetMapping("/getDict")
    public List<Dictionary> getDict(String type, String name, String code) {
        return sentenceService.getDict(type, name, code);
    }

}
